<?php
Yii::import('ext.validators.PhoneValidator');

class LichKhamForm extends CFormModel {
    
    public $full_name, $age, $sex, $address, $phone, $dateAppointment, $doctorName;
    public $verifyCode;

    public function init() {
        $this->sex = 'Nam';
    }
    public function rules() {
        return array(
            array('full_name, age, sex, address, phone, dateAppointment',
                'required',
                'message' => Yii::t('msg', 'please_input')
            ),
            array('verifyCode',
                'required',
                'message' => Yii::t('msg', 'verifycode_not_match')
            ),
            array('phone',
                'PhoneValidator',
                'message' => Yii::t('msg', 'incorret_format'),
            ),
            array('verifyCode', 'captcha',
                'allowEmpty' => false,
            ),
            array('age', 'numerical',
                'integerOnly' => true,
                'min'         => 1,
                'max'         => 150,
                'tooSmall'    => Yii::t('msg', 'incorret_format'),
                'tooBig'      => Yii::t('msg', 'incorret_format'),
            ),
            array('phone', 'length', 'max' => 32),
            array('doctorName', 'safe'),
        );
    }

    public function attributeLabels() {
        return array(
            'full_name'       => 'Họ và tên',
            'address'         => 'Địa chỉ',
            'phone'           => 'Điện thoại',
            'age'             => 'Tuổi',
            'sex'             => 'Giới tính',
            'dateAppointment' => 'Thời gian yêu cầu khám',
            'doctorName'      => 'Bác sĩ yêu cầu (nếu có)',
            'verifyCode'     => 'Gõ mã xác thực bên cạnh',
        );
    }

    /* ------------------------------------------------------------------------
      SEND MAIL
    -------------------------------------------------------------------------*/
    /**
     * Render attribute values to HTML format.
     * Support to send mail.
     * @return string
     */
    public function renderHtml() {
        $tplPath = Yii::app()->params['mail_template_dir'] . 'dat_lich_kham.txt';
        $result = null;
        
        if (is_file($tplPath)) {
            $content = file_get_contents($tplPath);
            $result = sprintf($content,
                $this->full_name,
                $this->age,
                $this->sex,
                $this->address,
                $this->phone,
                $this->dateAppointment,
                $this->doctorName
            );
        }
        
        return $result;
    }
    /* ------------------------------------------------------------------------
      //SEND MAIL
    -------------------------------------------------------------------------*/

}
